home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Creator Changer 2.7 / Code & Resource / Creator Changer.init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  7.0 KB  |  247 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the functions which initialize the toolbox
  3.  *    and check to see if System 7 is present, and loads the error 
  4.  *    strings into memory.
  5.  **********************************************************************/
  6.  
  7. #include    "QDOffscreen.h"
  8. #include    "Creator Changer.h"
  9. #include    "Creator Changer.init.h"
  10. #include    "AppleEvents.h"
  11. #include    "Folders.h"
  12.  
  13.  
  14. /**********************************************************************
  15.  *    Function Init_Toolbox(), this function initializes the Macintosh 
  16.  *    toolbox so that all of the parts of the program will work.
  17.  **********************************************************************/
  18.  
  19. void Init_Toolbox(void)
  20.     {
  21.         
  22.     InitGraf(&qd.thePort);
  23.     InitFonts();
  24.     FlushEvents(everyEvent, 0);
  25.     InitWindows();
  26.     InitMenus();
  27.     TEInit();
  28.     InitDialogs(NIL_PTR);
  29.     InitCursor();
  30.     
  31.     MaxApplZone();
  32.     MoreMasters();
  33.     MoreMasters();
  34.     
  35.     Chng.storage=NewPtr(sizeof(DialogRecord));
  36.     Pref.storage=NewPtr(sizeof(DialogRecord));
  37.     About.storage=NewPtr(sizeof(DialogRecord));
  38.  
  39.     Chng.menu_id=PREF_TYPES_ID;
  40.     Chng.pref_type=PREF_PT;
  41.     Chng.dlog_id=CHNG_TYPE_DLOG_ID;
  42.     Chng.num_items=0;
  43.     
  44.     Edit.menu_id=PREF_TYPES_ID;
  45.     Edit.pref_type=PREF_PT;
  46.     Edit.num_items=0;
  47.     
  48.     Auto.menu_id=AUTO_CHANGE_ID;
  49.     Auto.pref_type=PREF_AC;
  50.     Auto.num_items=0;
  51.     
  52.     About.dlog_id=ABOUT_DLOG_ID;
  53.     
  54.     Pref.menu_id=0;
  55.     Pref.dlog_id=PREF_DLOG_ID;
  56.     Pref.num_items=6;
  57.  
  58.     All_Done=FALSE;
  59.     Dialog_Opened=NO;
  60.     Maintain_Menu_Items(FrontWindow());
  61.     In_Background=FALSE;
  62.     Sleep_Ticks=10;
  63.     
  64.     }
  65.  
  66.  
  67.  
  68. /**********************************************************************
  69.  *    Function Get_Error_Messages(), this function gets the error
  70.  *    messages that are stored in the resources.
  71.  **********************************************************************/
  72.  
  73. void Get_Strings(void)
  74.     {
  75.     
  76.     GetIndString( Types_Error_1,  ERROR_STRING_LIST, TYPES_ERROR_1  );
  77.     GetIndString( Types_Error_2,  ERROR_STRING_LIST, TYPES_ERROR_2  );
  78.     GetIndString( Descr_Error,    ERROR_STRING_LIST, DESC_ERROR     );
  79.     GetIndString( Bad_Item_Error, ERROR_STRING_LIST, BAD_ITEM_ERROR );
  80.     GetIndString( Bad_CF_Type_1,  ERROR_STRING_LIST, BAD_CF_TYPE_1  );
  81.     GetIndString( Bad_CF_Type_2,  ERROR_STRING_LIST, BAD_CF_TYPE_2  );
  82.     GetIndString( Bad_CF_Type_3,  ERROR_STRING_LIST, BAD_CF_TYPE_3  );
  83.     GetIndString( Bad_CF_Type_4,  ERROR_STRING_LIST, BAD_CF_TYPE_4  );
  84.     GetIndString( Multi_File_1,   ERROR_STRING_LIST, MULTI_FILE_1   );
  85.     GetIndString( Multi_File_2,   ERROR_STRING_LIST, MULTI_FILE_2   );
  86.     GetIndString( Multi_File_3,   ERROR_STRING_LIST, MULTI_FILE_3   );
  87.     GetIndString( Pref_File_Name, MISC_STRING_LIST,  PREF_FILE_NAME );
  88.     
  89.     }
  90.  
  91.  
  92.  
  93. /**********************************************************************
  94.  *    Function Check_Sys_Type(), this function checks to see if System
  95.  *    seven or later is present, if it isn't then the program quits.
  96.  **********************************************************************/
  97.  
  98. void Check_Sys_Type(void)
  99.     {
  100.     
  101.     short        sys_7=0x0700;
  102.     short        vers_requsted=1;
  103.     SysEnvRec    the_environ;
  104.     
  105.     SysEnvirons(vers_requsted, &the_environ);
  106.     
  107.     if(the_environ.systemVersion>=sys_7) All_Done=FALSE;
  108.     else
  109.         {
  110.         GetIndString(Sys7_Error_1, ERROR_STRING_LIST, SYS7_ERROR_1);
  111.         GetIndString(Sys7_Error_2, ERROR_STRING_LIST, SYS7_ERROR_2);
  112.         Do_Error(Sys7_Error_1, EMPTY_STR, Sys7_Error_2, EMPTY_STR);
  113.         ExitToShell();
  114.         }
  115.     
  116.     }
  117.  
  118.  
  119. /**********************************************************************
  120.  *    Function Open_Preferences(), this function opens the preference
  121.  *    file that is used to set creator types.
  122.  **********************************************************************/
  123.  
  124. void Open_Preferences(void)
  125.     {
  126.     
  127.     Handle            pref_string, TMPL_handle[3], global_vals;
  128.     OSErr            file_Err;
  129.     short            i;
  130.     global_prefs    **global;
  131.     pref_types        **pt_handle[4];
  132.     auto_chng        **ac_handle[3];
  133.  
  134.     CreatorChangerApp=CurResFile();
  135.     
  136.     file_Err=FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &Pref_VRef, &Pref_Dir_ID);
  137.     if(file_Err==noErr) file_Err=FSMakeFSSpec(Pref_VRef, Pref_Dir_ID, Pref_File_Name, &Pref_Spec);
  138.     if(file_Err==fnfErr)
  139.         {
  140.         FSpCreateResFile(&Pref_Spec, 'CPrf', kPreferencesFolderType, -1);
  141.  
  142.         CreatorChangerPref=FSpOpenResFile(&Pref_Spec, 3);
  143.         
  144.         pref_string=(Handle)GetResource('STR ', -16397);
  145.         DetachResource(pref_string);
  146.         
  147.         global_vals=(Handle)GetResource('pref', Strt_Rsrc+7);
  148.         DetachResource(global_vals);
  149.         
  150.         TMPL_handle[1]=(Handle)GetResource('TMPL', 128);
  151.         DetachResource(TMPL_handle[1]);
  152.         TMPL_handle[2]=(Handle)GetResource('TMPL', 129);
  153.         DetachResource(TMPL_handle[2]);
  154.         TMPL_handle[3]=(Handle)GetResource('TMPL', 130);
  155.         DetachResource(TMPL_handle[3]);
  156.         
  157.         for(i=0;i<=3;i++)
  158.             {
  159.             pt_handle[i+1]=(pref_types **)GetResource('pref', Strt_Rsrc+i);
  160.             DetachResource((Handle)pt_handle[i+1]);
  161.             }
  162.         
  163.         for(i=4;i<=6;i++)
  164.             {
  165.             ac_handle[i-3]=(auto_chng **)GetResource('pref', Strt_Rsrc+i);
  166.             DetachResource((Handle)ac_handle[i-3]);
  167.             }
  168.  
  169.         UseResFile(CreatorChangerPref);
  170.         
  171.             AddResource(global_vals, PREF_GL, 128, NIL_PTR);
  172.             
  173.             AddResource(TMPL_handle[1], 'TMPL', 128, "\pCCpt");
  174.             AddResource(TMPL_handle[2], 'TMPL', 129, "\pCCgl");
  175.             AddResource(TMPL_handle[3], 'TMPL', 130, "\pCCac");
  176.             
  177.             AddResource(pref_string, 'STR ', -16397, NIL_PTR);
  178.             
  179.             for(i=0;i<=3;i++) AddResource((Handle)pt_handle[i+1], PREF_PT, Strt_Rsrc+i, (**pt_handle[i+1]).Description);
  180.             for(i=0;i<=2;i++) AddResource((Handle)ac_handle[i+1], PREF_AC, Strt_Rsrc+i, (**ac_handle[i+1]).Name);
  181.             
  182.             UpdateResFile(CreatorChangerPref);
  183.             
  184.             ReleaseResource(pref_string);
  185.             ReleaseResource(global_vals);
  186.             
  187.             for(i=1;i<=3;i++) ReleaseResource(TMPL_handle[i]);
  188.             for(i=1;i<=4;i++) ReleaseResource((Handle)pt_handle[i]);
  189.             for(i=1;i<=3;i++) ReleaseResource((Handle)ac_handle[i]);
  190.  
  191.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  192.             Auto.num_items=CountResources(PREF_AC);
  193.             
  194.             global=(global_prefs **)GetResource(PREF_GL, 128);
  195.             Global=global;
  196.         UseResFile(CreatorChangerApp);
  197.         }
  198.     else
  199.         {
  200.         CreatorChangerPref=FSpOpenResFile(&Pref_Spec, 3);
  201.  
  202.         UseResFile(CreatorChangerPref);
  203.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  204.             Auto.num_items=CountResources(PREF_AC);
  205.             global=(global_prefs **)GetResource(PREF_GL, 128);
  206.             Global=global;
  207.         UseResFile(CreatorChangerApp);
  208.         }
  209.     
  210.     }
  211.  
  212.  
  213.  
  214. /**********************************************************************
  215.  *    Function Set_Up_Menu_Bar(), this function displays the menu bar
  216.  *    for the program. 
  217.  **********************************************************************/
  218.  
  219. void Set_Up_Menu_Bar(void)
  220.     {
  221.     
  222.     Handle    menu_bar;
  223.     
  224.     menu_bar=GetNewMBar(MAIN_MENU_BAR_ID);
  225.     SetMenuBar(menu_bar);
  226.     Apple_Menu=GetMHandle(APPLE_MENU_ID);
  227.     File_Menu=GetMHandle(FILE_MENU_ID);
  228.     Edit_Menu=GetMHandle(EDIT_MENU_ID);
  229.     AddResMenu(Apple_Menu, 'DRVR');
  230.     DrawMenuBar();
  231.     
  232.     }
  233.  
  234.  
  235.  
  236. /**********************************************************************
  237.  *    Function Do_Error(), this function does the error routine.
  238.  **********************************************************************/
  239.  
  240. void Do_Error(StringPtr s1, StringPtr s2, StringPtr s3, StringPtr s4)
  241.     {
  242.     
  243.     ParamText(s1, s2, s3, s4);
  244.     Alert(ERROR_ALERT_ID, NIL_PTR);
  245.     
  246.     }
  247.